﻿using System.Collections.Generic;
using System.Diagnostics;
using NExplorer.Core.Commands;

namespace NExplorer.Core
{
    internal class VerbMenuBuilder : SingleCategoryMenuBuilder
    {
        protected override string Category
        {
            get { return "Verbs"; }
        }

        protected override void AddCommands()
        {
            SelectionInfo selectionInfo = ServiceManager.Explorer.SelectionInfo;
			
            if (selectionInfo.Extensions.Count == 1)
            {
                ProcessStartInfo startInfo = new ProcessStartInfo("dummy." + selectionInfo.Extensions[0].Value);
                string[] verbs = startInfo.Verbs;
				
                if (verbs.Length == 0)
                {
                    // No verbs associated; use Open instead.
                    Add<OpenCommand>();
                }
                else
                {
                    foreach (string verb in verbs)
                    {
                        ICommand command = VerbCommand.Create(verb);

                        if (command != null)
                        {
                            Add(command);
                        }
                    }
                }
            }
        }
    }
}